package com.smiletrain.activities;

import com.smiletrain.R;
import com.smiletrain.util.AdminCasos;
import com.smiletrain.util.Constantes;
import com.smiletrain.view.ItemCaso;
import com.smiletrain.view.ListaCaso;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

public class MisCasosActivity extends Activity {
	/**
	 * @see android.app.Activity#onCreate(Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		
		setContentView(R.layout.miscasos_view);
		
		ImageView atras = (ImageView) findViewById(R.id.bAtras);
        
        atras.setOnClickListener(new OnClickListener() {
        	
			@Override
			public void onClick(View v) {
				MisCasosActivity.this.onBackPressed();
			}
			
		});
        
        ImageView home = (ImageView) findViewById(R.id.imageViewX);
        
        home.setOnClickListener(new OnClickListener() {
        	
			@Override
			public void onClick(View v) {
				AdminCasos.instance.saveCasos();
				Intent intent = new Intent(MisCasosActivity.this, WellcomeActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
				overridePendingTransition(R.anim.in_anim, R.anim.back_anim);
			}
			
		});
        
	}
	
	@Override
	protected void onStart() {

		if(AdminCasos.instance.getCasos().length > 0) {
		
			ListView listView = (ListView) findViewById(R.id.lstCasos);
	
	        listView.setAdapter(new ListaCaso(AdminCasos.instance.getItemCasos()));
        
		} else {
			ListView listView = (ListView) findViewById(R.id.lstCasos);
			
	        listView.setAdapter(new ListaCaso(new ItemCaso[]{}));
			Toast.makeText(MisCasosActivity.this, Constantes.MSG_VAL01_V17, Toast.LENGTH_SHORT).show();
		}
		
		super.onStart();
	}
	
}
